package emp.jsf.servicio.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import emp.entidades.EntUbigeo;
import emp.jsf.servicio.UbigeoService;
import emp.repositorios.UbigeoRepository;

@Service("ubigeoService")
public class UbigeoServiceImpl implements UbigeoService{
	
	@Autowired
	UbigeoRepository ubigeoRepository;
	
	public List<EntUbigeo> listarUbigeos(){
		return ubigeoRepository.findAll();
	}
	
	public List<EntUbigeo> listarDepartamentos(){
		return ubigeoRepository.listarDepartamentos();
	}
	
	public List<EntUbigeo> listarProvincias(String id){
		return ubigeoRepository.listarUbigeoNivel(id);
	}
	
	public List<EntUbigeo> listarUbigeoNivel(String id){
		return ubigeoRepository.listarUbigeoNivel(id);
	}
	
	public List<EntUbigeo> listarUbigeoNivelPadre(String id){
		return ubigeoRepository.listarUbigeoNivelPadre(Long.valueOf(id));
	}
	
	public List<EntUbigeo> listarDistritos(String id){
		return ubigeoRepository.listarUbigeoNivel(id);
	}
	
	public EntUbigeo grabarUbigeo(EntUbigeo ent){
		return ubigeoRepository.saveAndFlush(ent);
	}
	
	public void eliminar(EntUbigeo ent){
		ubigeoRepository.delete(ent);
	}
}
